package com.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

@WebServlet("/shenfenzheng")
public class ShenfenzhengHttpServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String next = req.getParameter("next");
        Map<String, String> map = MapDemo.getMap();
        resp.setContentType("text/html;charset=utf-8");
        boolean flag = false;
        for (Map.Entry<String, String> entry : map.entrySet()) {
            if (entry.getKey().equals(next)) {
                 flag = true;
                resp.getWriter().write(entry.getValue());
            } else if (entry.getValue().equals(next)) {
                flag = true;
                resp.getWriter().write(entry.getKey());
            }
        }
        if (flag == false) {
            resp.getWriter().write("Sorry,not find");
        }

    }
}
